package net.studou.dao;

import java.util.List;
import net.studou.po.Smaller;

import org.springframework.stereotype.Component;

@Component("smallUserDao")
public class SmallUserDao extends CommonDao{
	public SmallUserDao(){
		super.clazz = Smaller.class;
	}
	
	@SuppressWarnings("unchecked")
	public Smaller findByNameAndUser(Smaller smaller){
		try {
			String hql = "from "+ Smaller.class.getName() + " m where m.smallUser = '" + smaller.getSmallUser() + "' and m.user.userId = " + smaller.getUser().getUserId();
			List<Smaller> list = getHibernateTemplate().find(hql);
			if(list != null && list.size() > 0){
				smaller = list.get(0);
			} else {
				smaller = null;
			}
		} catch (RuntimeException e) {
			throw e;
		}
		
		return smaller;
	}
	
}
